package personal.lijun.skeleton.web.access.intercept;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.SecurityConfig;
import org.springframework.security.web.util.matcher.AntPathRequestMatcher;
import org.springframework.stereotype.Repository;
import personal.lijun.skeleton.web.feign.SecurityFiltermetadataServiceFeign;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @Auther: lijun@sstcsoft.com
 * @Date: 2019/9/18 16:31
 */
@Repository("requestConfigMappingService")
public class RequestConfigMappingServiceImpl implements RequestConfigMappingService {

    @Autowired
    private SecurityFiltermetadataServiceFeign securityFiltermetadataServiceFeign;

    @Override
    public List<RequestConfigMapping> getRequestConfigMappings() {
        return securityFiltermetadataServiceFeign.getRequestConfigMappings().stream()
                .map(md->{
                    return new RequestConfigMapping(
                            new AntPathRequestMatcher(md.getAntPattern()),
                            new SecurityConfig(md.getExpression()));

                })
                .collect(Collectors.toList());
    }
}
